#!/bin/bash
versionNumber="8.0"
#替换适配器配置文件中的物理码
#适配器程序配置文件位置
oldfilename=/home/tuners/adapterClient/application.properties
newfilename=/home/tuners/TN9100-CV3.0/application.properties
#获取原适配器配置文件物理码
code1=$(grep "device.code" $oldfilename)
#获取现适配器配置文件物理码
code2=$(grep "device.code" $newfilename)
#判断是否包含物理码
compare=$(echo $code1 | grep "device.code")

if [ "$compare" != "" ]
	then
		#替换
		sed -i "s/$code2/$code1/g" $newfilename
fi

#DIR="$( cd"$( dirname"${BASH_SOURCE[0]}" )" && pwd )"
#先把Java程序中的所有文件拷贝到 /home/tuners/adapterClient 下面
cp ./TN9100-CV3.0/adapterClient.jar /home/tuners/adapterClient
cp ./TN9100-CV3.0/adapterClient.sh /home/tuners/adapterClient
cp ./TN9100-CV3.0/application.properties /home/tuners/adapterClient
cp ./TN9100-CV3.0/startup.sh /home/tuners/adapterClient
cp ./TN9100-CV3.0/大屏适配器背景.png /home/tuners/adapterClient

#赋予权限
chmod -R 777 /home/tuners/adapterClient/*
chmod -R 777 /home/tuners/TN9100-CV3.0/*
chmod -R 777 /home/tuners/mysql-shellV1.0/*

#判断mysql进程是否存在
procNumber=$(ps -ef |grep -w mysql|wc -l)
if [ ${procNumber} -ge 1 ]
	then
		#获取mysql的版本信息
		result=$(mysql -V)
		#比较版本信息
		compare=$(echo $result | grep "${versionNumber}")
		if [ "$compare" != "" ]
			then
				echo "进程存在，且版本为8.0，执行8.0脚本"
				#执行mysql8.0修改密码及数据初始化脚本，并重启mysql
				sudo sh /home/tuners/mysql-shellV1.0/updatekey8.sh
			else
				echo "进程存在，且版本不为8.0，执行5.37脚本"
				mysql -uroot -ptuners2012 -e"source /home/tuners/mysql-shellV1.0/adapterClient.sql"
				mysql -uroot -ptuners2012 -e"source /home/tuners/mysql-shellV1.0/updateKey.sql"
				#重启mysql
				sudo service mysql restart
		fi
	else
		#执行mysql安装脚本
		sudo bash /home/tuners/mysql-shellV1.0/install_mysql.sh
fi

#java环境软连接到sudo命令下
ln -s /home/tuners/adapterClient/jdk1.8.0_161/bin/java /usr/bin/
#重启java程序
sh /home/tuners/adapterClient/startup.sh
#执行大屏修复脚本
sh /home/tuners/TN9100-CV3.0/adapterClient.sh


